/* 
 * Modbus app for RTU.
 * Copyright (c) 2012  apleilx
 * All rights reserved.
 * no limite
 */

/* ----------------------- Platform includes --------------------------------*/
#define _MBAPP_MODULE_
#include "mbapp.h"
#include "osObjects.h"                                          // RTOS object definitions



/*****************************************************************************//*!
* @brief   	Slave device handle.
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/    
void ModbusTask (void  *p_arg)
{
    OS_ERR      p_err;
    CPU_TS      p_ts;
    
    OSTaskSemSet(&ModbusTaskTCB, 0, &p_err);
    mbxInit(RTU_SLAVE, 9600, MB_PAR_EVEN);
    mbxObj.SlaveId=2;
    
    for(;;){
        
        if(mbxObj.RunSt.bits.MasterMode){
            //OSTaskSemPend(20, OS_OPT_PEND_BLOCKING, &p_ts, &p_err);
        } else {
            OSTaskSemPend(SMB_TIME_OUT_MS, OS_OPT_PEND_BLOCKING, &p_ts, &p_err);
            //OSTimeDly (5, OS_OPT_TIME_DLY, &p_err);
            if(OS_ERR_TIMEOUT == p_err){
                mbxObj.RcvSt = MB_RX_TIMEOUT;
            } else {
            
            }
            mbSlavePoll(&mbxObj);
        }
        
    }
}




